<?php

namespace App\Http\Controllers\Vadmin;

use Illuminate\Http\Request;
use DB;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Session;
class LoginController extends Controller
{
    public function login()
	{
		return view('Vadmin/login');
	}
	
	public function checkLogin(Request $request){
		//ECHO 'ASFASDF';
		//接受表单信息
		$uname=$request->input('uname');
		$upwd=md5($request->input('upwd'));
		//dd($request);
		$result=DB::table('user')
						->select('uid','uname','uemail','uauth')
						->where('uname','=',$uname)
						->where('upwd','=',$upwd)
						->first();
		//dd($result);
		//验证用户是否存在和密码是否正确权限是否为1
		if($result['uauth']==1){
			$request->session()->put('uid', $result['uid']);//用户id
			$request->session()->put('uname', $result['uname']);//用户名称
			$request->session()->put('uemail', $result['uemail']);//用户名称
			$request->session()->put('uauth', $result['uauth']);//用户名称
			
			return redirect('/vadmin/index');
		}else{
			return redirect('/vadmin/login');
		} 
		
		
	}
	//退出登录方法
	public function logout(Request $request)
	{
		
		//清除session信息
		$request->session()->flush();
		//跳转页面
		return redirect('/vadmin/login');
	}
}
